import 'package:flutter/material.dart';
import 'package:personinfo/model/home/SearchCarModel.dart';
import 'package:personinfo/utils/ColorUtil.dart';
import 'package:personinfo/widgets/common/CommonWidget.dart';
import 'package:personinfo/widgets/common/LineNav.dart';
import 'package:personinfo/widgets/common/MiniTitleNav.dart';
import 'package:personinfo/widgets/common/Vanfeild.dart';

class SelectCarInterior extends StatefulWidget {
  SearchCarModel arguments;
  SelectCarInterior({super.key, required this.arguments});
  @override
  _SelectCarInteriorState  createState() => _SelectCarInteriorState();
}

class _SelectCarInteriorState extends State<SelectCarInterior>  {
  TextEditingController customColor=TextEditingController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    print(widget.arguments);
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      backgroundColor: Theme.of(context).colorScheme.onPrimary,
      appBar: commonWidget.appBar(
          title: const Text("选择内饰"),
          leading: GestureDetector(
            onTap: () {
              Navigator.pop(context);
            },
            child: const Icon(Icons.keyboard_arrow_left),
          )
      ),
      body: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            MiniTitleNav(title: "内饰",showMore: false),
            ...["红色","白内部寻车","黑","蓝","紫","金","不限"].map((index)=> VandInfo(
                labelText: '$index',
                onTap: (){
                  widget.arguments.carInterior = index;
                  Navigator.pushReplacementNamed(context, '/publishSearchCar',arguments: widget.arguments);
                }
            )
            ).toList(),
            MiniTitleNav(title: "自定义内饰",showMore: false),
            Container(
              padding: EdgeInsets.fromLTRB(20, 12, 20, 10),
              decoration: BoxDecoration(
                border: Border(
                  // 划线位置、线宽、颜色
                  bottom: BorderSide(width: 1.0, color: Color.fromRGBO(214, 214, 214, 1)),
                ),
              ),
              child: TextFormField(
                controller: customColor,
                decoration: InputDecoration(
                  hintText: "请输入自定义颜色",
                  hintStyle: TextStyle(
                      fontSize: 14,
                      color: Color.fromRGBO(153, 153, 153, 1)
                  ),
                  border: InputBorder.none,
                ),  
              ),
            ),
            Container(
              margin: EdgeInsets.fromLTRB(20, 10, 20, 0),

              child: OutlinedButton(
                style:  ElevatedButton.styleFrom(
                  backgroundColor: Colors.white, // 白色背景
                  foregroundColor: Color.fromRGBO(254, 108, 67, 1), // 橙色文字
                  elevation: 0, // 去除阴影
                  side: BorderSide(
                    color: Color.fromRGBO(254, 108, 67, 1), // 橙色边框
                    width: 1.0,
                  ),
                  padding: EdgeInsets.symmetric(horizontal: 30, vertical: 12),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.zero, // 去除圆角
                  ),
                ),
                onPressed: (){
                  if(customColor.text.isEmpty){
                    ScaffoldMessenger.of(context).showSnackBar(
                      SnackBar(content: Text('请输入自定义内饰颜色')),
                    );
                    return;
                  }
                  widget.arguments.carInterior = customColor.text;
                  Navigator.pushReplacementNamed(context, '/publishSearchCar',arguments: widget.arguments);
                }, child: Text("保存"),
              ),
            ),
            lineNav.miniLine()
          ]
      ),
    );
  }
}
